module ProgramCounter (
	
	input clk,					//Clock Signal (100Hz or 1Hz)
	input [7:0] ResetVal,	//input value to update the PC wehn load is active
	input [7:0] LoadVal,		//input value to update the PC when reset is active
	input reset,					//An active-high singal to rest the PC (exectute without clk)
	input load,					//An active-high signal to load value in PC (function activated with clk)
	input inc,					//An active-high singal to start the counting
	input Mode,
	
	output reg [7:0] PCoutput	//PC output signal in binary

);
	reg last_Mode;

	initial begin
		PCoutput = 8'd0;
		last_Mode = 1'b0;
	end

	always @(posedge clk or posedge reset) begin
		if (reset) begin
			PCoutput <= ResetVal;
			last_Mode <= Mode;
		end
		else if (load) begin
			PCoutput <= LoadVal;
			last_Mode <= Mode;
		end
		else if (Mode != last_Mode) begin
			PCoutput <= 8'd0;
			last_Mode <= Mode;
		end
		else if (inc) begin
			if (PCoutput < 8'd255)
				PCoutput <= PCoutput + 1;
			else if (PCoutput == 8'd255)
				PCoutput <= 8'd0;
		end
	end

endmodule
